Option Explicit On
Option Strict On

Imports System.Collections.Generic
Imports nstl
Imports NUnit.Framework
Imports NStl.SyntaxHelper


Namespace nstl.test
    <TestFixture()> _
    Public Class MultimapTest
        Inherits IDictionaryTest
        ''' <summary>
        ''' Initialize() is called once during test execution before
        ''' test methods in this test class are executed.
        ''' </summary>
        <SetUp()> _
        Public Overrides Sub SetUp()
            MyBase.SetUp()

            _m = New MultiMap(Of Integer, String)(Compare.Less(Of Integer)())

            For i As Integer = 0 To _keys.Length - 1
                _m.Insert(_keys(i), _vals(i))
            Next
        End Sub

        ''' <summary>
        ''' Cleanup() is called once during test execution after
        ''' test methods in this class have executed unless the
        ''' corresponding Initialize() call threw an exception.
        ''' </summary>
        <TearDown()> _
        Public Overrides Sub TearDown()
            _m = Nothing

            MyBase.TearDown()
        End Sub
        Private _m As MultiMap(Of Integer, String)
        Private _keys As Integer() = New Integer() {0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9}
        Private _vals As String() = New String() {"0", "00", "1", "2", "22", "3", "4", "44", "5", "6", "66", "7", "8", "88", "9"}

        Protected Overrides Function CreateDictionary() As IDictionary(Of Integer, String)
            Return New MultiMap(Of Integer, String)(Compare.Less(Of Integer))
        End Function


        <Test()> _
        Public Sub MultiInsert()
            Assert.IsFalse(TestUtil.mismatch(_m, _keys, _vals))
        End Sub

        <Test()> _
        Public Sub EraseTest()
            Dim it As MultiMap(Of Integer, String).Iterator = _m.Find(4)
            _m.Erase(it)

            Dim keys As Integer() = New Integer() {0, 0, 1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 8, 9}
            Dim vals As String() = New String() {"0", "00", "1", "2", "22", "3", "44", "5", "6", "66", "7", "8", "88", "9"}
            Assert.IsFalse(TestUtil.mismatch(_m, keys, vals))

        End Sub

        <Test()> _
        Public Sub find()
            Assert.AreNotEqual(_m.Find(4), _m.End())
            Assert.AreEqual(_m.Find(42), _m.End())
        End Sub

        <Test()> _
        Public Sub TestIInsertableImp()
            Dim v As New List(Of Integer)(New Integer() {1, 5, 3, 4, 2, 6, 7, 8, 0, 9})

            Dim m As New MultiMap(Of Integer, String)(Compare.Less(Of Integer)())

            Algorithm.Transform(v.Begin, v.End, m.InsertIterator(m.Begin), New Vec2Map)

            Assert.IsFalse(TestUtil.mismatch(m, New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, New String() {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}))

        End Sub

    End Class

End Namespace

